import request from '@/router/axios'
import {
  approveStatus, fenExYuangettoFixed,
  getApproveStatus,
  getLineName,
  getreplayStatusFormat,
  getStationName,
  qianxiangType
} from "../../commonCheck";

import store from '@/store';

export const tableOption = {
  emptyBtn:false,
  border: true,
  index: true,
  indexLabel: '序号',
  selection: true,
  reserveSelection:true,
  stripe: true,
  menuWidth:150,
  menuAlign: 'center',
  editBtn: false,
  delBtn: false,
  align: 'center',
  addBtn: false,
  height: 500,
  column: [{label:"线路",width: 100,
    prop:"lineCode",type:'select',search:true,searchslot:true,formatter: function(row, value , label, column){
      return getLineName(value);
    }},
    {label:"站点",width: 180,
      prop:"stationCode",type:'select',search:true,searchslot:true,formatter: function(row, value , label, column){
        return getStationName(row.lineCode,value);
      }},
    {label:"结算周期",width: 100,
      prop:"settlementPeriod",search:false,hide:true},
    {label:"开始日期",
      prop:"startTime",search:true,type:'date',
      width: 100,valueFormat:'yyyy-MM-dd'},
    {label:"结束日期",
      prop:"endTime",search:true,type:'date',
      width: 100,valueFormat:'yyyy-MM-dd'},
    {label:"收益日期",
      prop:"revenueDate",search:true,type:'date',
      width: 100,valueFormat:'yyyy-MM-dd'},
    {label:"设备编号",search:true,type:'select',searchslot:true,
      prop:"equipmentCode"},
    {label:"发售数量(合计)",width: 140,
      prop:"totalNumberSales"},
    {label:"对比发售数量(合计)",width: 160,
      prop:"compareTotalNumberSales"},
    {label:"差异数量", formatter:function(row, value , label, column){
        row.chayifashou=Number(row.totalNumberSales) - Number(row.compareTotalNumberSales);
        return Number(row.totalNumberSales) - Number(row.compareTotalNumberSales);
      },
      prop:"chayifashou"},
    {label:"小计金额(合计)",width: 140,
      prop:"subtotalTotal",formatter:function (row,value) {
          return fenExYuangettoFixed(row,'subtotalTotal');
      }},
    {label:"对比小计金额(合计)",width: 160,
      prop:"compareSubtotalTotal",formatter:function (row,value) {
        return fenExYuangettoFixed(row,'compareSubtotalTotal');
      }},
    {label:"差异金额",
        prop:"chayije",formatter:function(row, value , label, column){
        row.chayije=Number(row.subtotalTotal) - Number(row.compareSubtotalTotal);
        return fenExYuangettoFixed(row,"chayije");
      },
      prop:"chayije"},
    {label:"协查确认金额",hide:true,width: 120,
      prop:"assistAmount",formatter:function (row,value) {
        return fenExYuangettoFixed(row,'assistAmount');
      }},
    {label:"确认金额",
      prop:"confirmAmount",formatter:function (row,value) {
      if(Number(row.chayije)==0){//差异金额为0时，则使用小计金额
        row.confirmAmount = Number(row.subtotalTotal);
        return fenExYuangettoFixed(row,'confirmAmount');
      }else{
        return fenExYuangettoFixed(row,'confirmAmount');
      }

      }},
    {label:"确认数量",
      prop:"confirmNumber",
    },
    {label:"差异原因",
      prop:"diffReason",
    },
    {label:"备注",
      prop:"remark",
    },{
      hide: false,width: 160,
      label: '是否加入报表差错',
      prop: 'isAddReprotError',
      type:'select',
      search: true,
	    searchLabelWidth:130,
      formatter:function(row, value , label, column){
        return value==0?'否':(value==1)?'是':'';
      },
      dicData: [{
        label: '是',
        value: '1'
      },{
        label: '否',
        value: '0'
      }]
    },
    {label:"审批状态",
    prop:"approvalStatus",type:'select',
    search: true,
    dicData: [{
      label: '审批通过',
      value: 1
    },{
      label: '未审批',
      value: 0
    }],
    formatter:function(row, value , label, column){
      return value==0?'未审批':(value==1)?'审批通过':'';
    }
    // dicData:approveStatus(),formatter:function(row, value , label, column){
    //   return value==0?'未审批':(value==1)?'审批通过':'';
    // },
    }
  ]
}

export function getSwAuInputInternetTicketEquipmentList(query) {
  return request({
    url: '/check/check/getSwAuInputInternetTicketEquipmentList',
    method: 'post',
    params: query
  })
}

export function approvePassSwAuInputInternetTicketEquipment(param){
  return request({
    url: '/check/check/approvePassSwAuInputInternetTicketEquipment',
    method: 'post',
    params: param
  })
}

export function getIds(rows) {
  let ids=[];
  let chaYiIds=[];
  for(let i=0;i<rows.length;i++){
    if(Number(rows[i].chayije)==0){
      chaYiIds.push(rows[i].id);
    }
    ids.push(rows[i].id);
  }
  let res={};
  res.ids=ids.join(",");
  res.chaYiIds=chaYiIds.join(",");
  return res;
}

/**
 * 车站明细详情
 * @param param
 */
export function getSwStInputInternetTicketEquipmentDetails(param){
  return request({
    url: '/check/check/getSwStInputInternetTicketEquipmentDetails',
    method: 'post',
    params: param
  })
}

/**
 * 收入审核明细详情
 * @param param
 */
export function getSwAuInputInternetTicketEquipmentDetails(param){
  return request({
    url: '/check/check/getSwAuInputInternetTicketEquipmentDetails',
    method: 'post',
    params: param
  })
}

/**
 * 修改互联网售票机数据
 * @param param
 */
export function updateSwAuInputInternetTicketEquipment(param){
  return request({
    url: '/check/check/updateSwAuInputInternetTicketEquipment',
    method: 'post',
    params: param
  })
}

/**
 * 替换确认金额为协查金额
 * @param param
 */
export function replaceSwAuInputInternetTicketEquipmentJine(param){
  return request({
    url: '/check/check/replaceSwAuInputInternetTicketEquipmentJine',
    method: 'post',
    params: param
  })
}


/**
 * 替换确认金额为协查金额
 * @param param
 */
export function getLineCodeWithSwAuInputInternetTicketEquipment(param){
  return request({
    url: '/check/check/getLineCodeWithSwAuInputInternetTicketEquipment',
    method: 'post',
    params: param
  })
}

/**
 * 互联网售票机导出分线路
 * @param {} param
 * @returns
 */
 export function exportInternetTicketEquipmentLine(param) {
  return request({
    url: '/check/check/exportInternetTicketEquipmentLine',
    method: 'get',
    params: param,
    responseType:'blob'
  })
}

/**
 * 互联网售票机导出分日期
 * @param {} param
 * @returns
 */
export function exportInternetTicketEquipmentDate(param) {
  return request({
    url: '/check/check/exportInternetTicketEquipmentDate',
    method: 'post',
    params: param
  })
}

/**
 * 协查导出
 * @param param
 */
export function xcExportDataSwAuInputInternetTicketEquipments(param) {
  return request({
    url: '/check/check/xcExportDataSwAuInputInternetTicketEquipments',
    method: 'post',
    params: param,
    responseType:'arraybuffer'
  })
}

/**
 * 协查导出
 * @param query
 */
export function exportInternet(query) {
  return request({
    url: '/check/check/exportInternet',
    method: 'get',
    params: query,
    responseType:'blob'
  })
}
